Let's import all necessary libraries for the analysis and along with it let's bring down our dataset
import pandas as pd
this time I will let you start from the very beginning by downloading and exploring data on your own from Kaggle https://www.kaggle.com/benroshan/online-food-delivery-preferencesbangalore-region
df =pd.read_csv('onlinedeliverydata.csv')
df.head()
| Age | Gender | Marital Status | Occupation | Monthly Income | Educational Qualifications | Family size | latitude | longitude | Pin code | ... | Less Delivery time | High Quality of package | Number of calls | Politeness | Freshness | Temperature | Good Taste | Good Quantity | Output | Reviews | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 20 | Female | Single | Student | No Income | Post Graduate | 4 | 12.9766 | 77.5993 | 560001 | ... | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Yes | Nil\n |
| 1 | 24 | Female | Single | Student | Below Rs.10000 | Graduate | 3 | 12.9770 | 77.5773 | 560009 | ... | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Yes | Nil |
| 2 | 22 | Male | Single | Student | Below Rs.10000 | Post Graduate | 3 | 12.9551 | 77.6593 | 560017 | ... | Important | Very Important | Moderately Important | Very Important | Very Important | Important | Very Important | Moderately Important | Yes | Many a times payment gateways are an issue, so... |
| 3 | 22 | Female | Single | Student | No Income | Graduate | 6 | 12.9473 | 77.5616 | 560019 | ... | Very Important | Important | Moderately Important | Very Important | Very Important | Very Important | Very Important | Important | Yes | nil |
| 4 | 22 | Male | Single | Student | Below Rs.10000 | Post Graduate | 4 | 12.9850 | 77.5533 | 560010 | ... | Important | Important | Moderately Important | Important | Important | Important | Very Important | Very Important | Yes | NIL |
5 rows × 55 columns
if you want to show all columns just change pandas options!
pd.set_option('max_columns', 100) #Display up to 100 columns you can also do it for rows !
#pd.set_option("display.max_rows", 100)
df.head(5)
| Age | Gender | Marital Status | Occupation | Monthly Income | Educational Qualifications | Family size | latitude | longitude | Pin code | Medium (P1) | Medium (P2) | Meal(P1) | Meal(P2) | Perference(P1) | Perference(P2) | Ease and convenient | Time saving | More restaurant choices | Easy Payment option | More Offers and Discount | Good Food quality | Good Tracking system | Self Cooking | Health Concern | Late Delivery | Poor Hygiene | Bad past experience | Unavailability | Unaffordable | Long delivery time | Delay of delivery person getting assigned | Delay of delivery person picking up food | Wrong order delivered | Missing item | Order placed by mistake | Influence of time | Order Time | Maximum wait time | Residence in busy location | Google Maps Accuracy | Good Road Condition | Low quantity low time | Delivery person ability | Influence of rating | Less Delivery time | High Quality of package | Number of calls | Politeness | Freshness | Temperature | Good Taste | Good Quantity | Output | Reviews | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 20 | Female | Single | Student | No Income | Post Graduate | 4 | 12.9766 | 77.5993 | 560001 | Food delivery apps | Web browser | Breakfast | Lunch | Non Veg foods (Lunch / Dinner) | Bakery items (snacks) | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Agree | Agree | Agree | Agree | Agree | Agree | Yes | Weekend (Sat & Sun) | 30 minutes | Agree | Neutral | Neutral | Neutral | Neutral | Yes | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Yes | Nil\n |
| 1 | 24 | Female | Single | Student | Below Rs.10000 | Graduate | 3 | 12.9770 | 77.5773 | 560009 | Food delivery apps | Web browser | Snacks | Dinner | Non Veg foods (Lunch / Dinner) | Veg foods (Breakfast / Lunch / Dinner) | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Neutral | Agree | Strongly agree | Strongly agree | Agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Yes | Anytime (Mon-Sun) | 30 minutes | Strongly Agree | Neutral | Disagree | Strongly disagree | Agree | Yes | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Yes | Nil |
| 2 | 22 | Male | Single | Student | Below Rs.10000 | Post Graduate | 3 | 12.9551 | 77.6593 | 560017 | Food delivery apps | Direct call | Lunch | Snacks | Non Veg foods (Lunch / Dinner) | Ice cream / Cool drinks | Strongly agree | Strongly agree | Strongly agree | Neutral | Neutral | Disagree | Neutral | Disagree | Neutral | Neutral | Agree | Agree | Agree | Agree | Agree | Agree | Agree | Strongly agree | Agree | Neutral | Yes | Anytime (Mon-Sun) | 45 minutes | Agree | Strongly Agree | Neutral | Neutral | Agree | Yes | Important | Very Important | Moderately Important | Very Important | Very Important | Important | Very Important | Moderately Important | Yes | Many a times payment gateways are an issue, so... |
| 3 | 22 | Female | Single | Student | No Income | Graduate | 6 | 12.9473 | 77.5616 | 560019 | Food delivery apps | Walk-in | Snacks | Dinner | Veg foods (Breakfast / Lunch / Dinner) | Bakery items (snacks) | Agree | Agree | Strongly agree | Agree | Strongly agree | Agree | Agree | Agree | Strongly agree | Neutral | Agree | Disagree | Disagree | Neutral | Agree | Agree | Agree | Disagree | Disagree | Neutral | Yes | Anytime (Mon-Sun) | 30 minutes | Disagree | Agree | Agree | Neutral | Agree | Yes | Very Important | Important | Moderately Important | Very Important | Very Important | Very Important | Very Important | Important | Yes | nil |
| 4 | 22 | Male | Single | Student | Below Rs.10000 | Post Graduate | 4 | 12.9850 | 77.5533 | 560010 | Walk-in | Direct call | Lunch | Dinner | Non Veg foods (Lunch / Dinner) | Veg foods (Breakfast / Lunch / Dinner) | Agree | Agree | Agree | Agree | Agree | Neutral | Neutral | Agree | Strongly agree | Strongly agree | Agree | Strongly agree | Agree | Disagree | Strongly agree | Strongly agree | Neutral | Neutral | Neutral | Disagree | Yes | Weekend (Sat & Sun) | 30 minutes | Agree | Agree | Agree | Agree | Agree | Yes | Important | Important | Moderately Important | Important | Important | Important | Very Important | Very Important | Yes | NIL |
Insights
This Data Can be splitted into 8 Groups.
df.describe()
| Age | Family size | latitude | longitude | Pin code | |
|---|---|---|---|---|---|
| count | 388.000000 | 388.000000 | 388.000000 | 388.000000 | 388.000000 |
| mean | 24.628866 | 3.280928 | 12.972058 | 77.600160 | 560040.113402 |
| std | 2.975593 | 1.351025 | 0.044489 | 0.051354 | 31.399609 |
| min | 18.000000 | 1.000000 | 12.865200 | 77.484200 | 560001.000000 |
| 25% | 23.000000 | 2.000000 | 12.936900 | 77.565275 | 560010.750000 |
| 50% | 24.000000 | 3.000000 | 12.977000 | 77.592100 | 560033.500000 |
| 75% | 26.000000 | 4.000000 | 12.997025 | 77.630900 | 560068.000000 |
| max | 33.000000 | 6.000000 | 13.102000 | 77.758200 | 560109.000000 |
Insights:
import numpy as np
# Note:
# pd.pivot table ( df , categorical columns as index ,
# numerical columns as values , aggregation functions as list of func )
delivery_pivot1=pd.pivot_table(df,index=["Gender","Marital Status"],
values=['Age','Family size'],
aggfunc=[np.mean,len], margins=True)
delivery_pivot1
| mean | len | ||||
|---|---|---|---|---|---|
| Age | Family size | Age | Family size | ||
| Gender | Marital Status | ||||
| Female | Married | 27.265306 | 3.653061 | 49 | 49 |
| Prefer not to say | 26.000000 | 4.000000 | 5 | 5 | |
| Single | 23.098214 | 3.276786 | 112 | 112 | |
| Male | Married | 28.016949 | 3.864407 | 59 | 59 |
| Prefer not to say | 27.285714 | 1.571429 | 7 | 7 | |
| Single | 23.455128 | 3.000000 | 156 | 156 | |
| All | 24.628866 | 3.280928 | 388 | 388 | |
delivery_pivot2=pd.pivot_table(df,index=["Gender"],
values=['Age','Family size'],
aggfunc=[np.median,len], margins=True)
delivery_pivot2
| median | len | |||
|---|---|---|---|---|
| Age | Family size | Age | Family size | |
| Gender | ||||
| Female | 24.0 | 3 | 166 | 166 |
| Male | 24.5 | 3 | 222 | 222 |
| All | 24.0 | 3 | 388 | 388 |
Insights:
delivery_pivot3=pd.pivot_table(df,index=["Occupation","Monthly Income"],
values=['Age','Family size'],
aggfunc=[np.mean, np.median,len], margins=True)
delivery_pivot3
| mean | median | len | |||||
|---|---|---|---|---|---|---|---|
| Age | Family size | Age | Family size | Age | Family size | ||
| Occupation | Monthly Income | ||||||
| Employee | 10001 to 25000 | 24.304348 | 3.086957 | 24 | 3 | 23 | 23 |
| 25001 to 50000 | 26.750000 | 3.134615 | 27 | 3 | 52 | 52 | |
| Below Rs.10000 | 26.250000 | 2.625000 | 26 | 2 | 8 | 8 | |
| More than 50000 | 27.885714 | 3.771429 | 27 | 4 | 35 | 35 | |
| House wife | No Income | 30.333333 | 4.777778 | 31 | 5 | 9 | 9 |
| Self Employeed | 10001 to 25000 | 26.066667 | 3.266667 | 26 | 3 | 15 | 15 |
| 25001 to 50000 | 26.000000 | 3.857143 | 26 | 3 | 14 | 14 | |
| More than 50000 | 26.800000 | 3.480000 | 26 | 3 | 25 | 25 | |
| Student | 10001 to 25000 | 23.714286 | 3.571429 | 24 | 3 | 7 | 7 |
| 25001 to 50000 | 23.000000 | 2.333333 | 23 | 3 | 3 | 3 | |
| Below Rs.10000 | 22.764706 | 3.058824 | 22 | 3 | 17 | 17 | |
| More than 50000 | 23.000000 | 3.000000 | 23 | 3 | 2 | 2 | |
| No Income | 22.775281 | 3.162921 | 23 | 3 | 178 | 178 | |
| All | 24.628866 | 3.280928 | 24 | 3 | 388 | 388 | |
delivery_pivot4=pd.pivot_table(df,index=["Monthly Income"],
values=['Age','Family size'],
aggfunc=[np.mean, np.median,len], margins=True)
delivery_pivot4
| mean | median | len | ||||
|---|---|---|---|---|---|---|
| Age | Family size | Age | Family size | Age | Family size | |
| Monthly Income | ||||||
| 10001 to 25000 | 24.800000 | 3.222222 | 25 | 3 | 45 | 45 |
| 25001 to 50000 | 26.434783 | 3.246377 | 26 | 3 | 69 | 69 |
| Below Rs.10000 | 23.880000 | 2.920000 | 23 | 3 | 25 | 25 |
| More than 50000 | 27.290323 | 3.629032 | 27 | 3 | 62 | 62 |
| No Income | 23.139037 | 3.240642 | 23 | 3 | 187 | 187 |
| All | 24.628866 | 3.280928 | 24 | 3 | 388 | 388 |
Insights:
delivery_pivot3_=pd.pivot_table(df,index=["Educational Qualifications","Occupation"],
values=['Age','Family size'],
aggfunc=[np.mean,len])
#Adding bar for numbers
delivery_pivot3_.style.bar()
| mean | len | ||||
|---|---|---|---|---|---|
| Age | Family size | Age | Family size | ||
| Educational Qualifications | Occupation | ||||
| Graduate | Employee | 26.514706 | 3.250000 | 68 | 68 |
| House wife | 31.666667 | 4.333333 | 3 | 3 | |
| Self Employeed | 26.655172 | 3.862069 | 29 | 29 | |
| Student | 21.987013 | 3.038961 | 77 | 77 | |
| Ph.D | Employee | 28.000000 | 4.083333 | 12 | 12 |
| Self Employeed | 24.666667 | 3.000000 | 3 | 3 | |
| Student | 25.250000 | 3.375000 | 8 | 8 | |
| Post Graduate | Employee | 26.236842 | 3.078947 | 38 | 38 |
| Self Employeed | 25.571429 | 2.785714 | 14 | 14 | |
| Student | 23.172131 | 3.213115 | 122 | 122 | |
| School | House wife | 29.200000 | 5.400000 | 5 | 5 |
| Self Employeed | 27.142857 | 3.714286 | 7 | 7 | |
| Uneducated | House wife | 32.000000 | 3.000000 | 1 | 1 |
| Self Employeed | 30.000000 | 4.000000 | 1 | 1 | |
Insights:
import plotly.express as px
fig = px.histogram(df, x="Age")
fig.show()
fig = px.bar(df, x="Gender")
fig.show()
from matplotlib import pyplot as plt
import seaborn as sns
demog = ['Age', 'Gender', 'Marital Status',"Occupation", 'Monthly Income', "Educational Qualifications", 'Family size']
_, axes = plt.subplots(1, len(demog), figsize=(35, 5))
for i, feat in enumerate(demog):
sns.countplot(x=feat, data=df, ax=axes[i])
plt.show()
Insights of Group 1 [Demographics] :
peref= ['Medium (P1)', 'Medium (P2)', 'Meal(P1)', 'Meal(P2)', 'Perference(P1)', 'Perference(P2)']
_, axes = plt.subplots(1, len(peref), figsize=(35, 5))
for i, feat in enumerate(peref):
sns.countplot(x=feat, data=df, ax=axes[i])
plt.show()
Insights of Group 2 [Perefrences]:
satis = ['Ease and convenient', 'Time saving', 'More restaurant choices', 'Easy Payment option', 'More Offers and Discount', 'Good Food quality', 'Good Tracking system']
_, axes = plt.subplots(1, len(satis), figsize=(35, 5))
for i, feat in enumerate(satis):
sns.countplot(x=feat, data=df, ax=axes[i])
plt.show()
Insights of Group 3 [Satisfaction] :
purc = ['Self Cooking', 'Health Concern', 'Late Delivery', 'Poor Hygiene', 'Bad past experience', 'Unavailability', 'Unaffordable']
_, axes = plt.subplots(1, len(purc), figsize=(80, 5))
for i, feat in enumerate(purc):
sns.countplot(x=feat, data=df, ax=axes[i])
plt.show()
Insights of Group 4 [Not Purchasing] :
canc = ['Long delivery time', 'Delay of delivery person getting assigned', 'Delay of delivery person picking up food', 'Wrong order delivered', 'Missing item', 'Order placed by mistake']
_, axes = plt.subplots(1, len(canc), figsize=(80, 5))
for i, feat in enumerate(canc):
sns.countplot(x=feat, data=df, ax=axes[i])
plt.show()
Insights of Group 5 [Cancellation] :
perf = ['Influence of time', 'Order Time', 'Maximum wait time', 'Residence in busy location', 'Google Maps Accuracy', 'Good Road Condition', 'Low quantity low time', 'Delivery person ability']
_, axes = plt.subplots(1, len(perf), figsize=(80, 5))
for i, feat in enumerate(perf):
sns.countplot(x=feat, data=df, ax=axes[i])
plt.show()
Insights of Group 6 [Perefreneces] :
loyl = ['Influence of rating', 'Less Delivery time', 'High Quality of package', 'Number of calls', 'Politeness', 'Freshness ', 'Temperature', 'Good Taste ', 'Good Quantity', 'Output']
_, axes = plt.subplots(1, len(loyl), figsize=(80, 5))
for i, feat in enumerate(loyl):
sns.countplot(x=feat, data=df, ax=axes[i])
plt.show()
Insights of Group 7 [Loyality] :
Multivariate analysis between all groups.
Insights:
# 1. Gender vs Good Food quality
sns.countplot(x='Gender', hue='Good Food quality', data=df)
<AxesSubplot:xlabel='Gender', ylabel='count'>
import plotly.express as px
# 1. Gender vs Good Food quality
fig = px.sunburst(data_frame=df, path=('Gender', 'Good Food quality'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 2. Gender vs self cooking
fig = px.sunburst(data_frame=df, path=('Gender', 'Self Cooking'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 3. Marital status vs self cooking
fig = px.sunburst(data_frame=df, path=('Marital Status', 'Self Cooking'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 4. Monthly income vs Health concern
fig = px.sunburst(data_frame=df, path=('Monthly Income', 'Health Concern'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 5. Occupation vs Poor Hygiene
fig = px.sunburst(data_frame=df, path=('Occupation', 'Poor Hygiene'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 6. Family size vs Bad past experience
fig = px.sunburst(data_frame=df, path=('Family size', 'Bad past experience'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 7. Educational Qualifications vs Poor Hygiene
fig = px.sunburst(data_frame=df, path=('Educational Qualifications', 'Poor Hygiene'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 8. Gender vs Long Delivery Time
fig = px.sunburst(data_frame=df, path=('Gender', 'Long delivery time'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 9. Age vs Long Order delivered
fig = px.sunburst(data_frame=df, path=('Age', 'Wrong order delivered'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 10. Occupation vs Missing item
fig = px.sunburst(data_frame=df, path=('Occupation', 'Missing item'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 11. Monthly Income vs Order Placed by mistake
fig = px.sunburst(data_frame=df, path=('Monthly Income', 'Order placed by mistake'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 12. Family Size vs Influence of time
fig = px.sunburst(data_frame=df, path=('Family size', 'Influence of time'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 13. Occupation vs Influence of time
fig = px.sunburst(data_frame=df, path=('Occupation', 'Influence of time'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 14. Marital Status vs Output
fig = px.sunburst(data_frame=df, path=('Marital Status', 'Output'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 15. Monthly Income vs More Offers and Discount
fig = px.sunburst(data_frame=df, path=('Monthly Income', 'More Offers and Discount'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 16. Monthly Income vs Good Food quality
fig = px.sunburst(data_frame=df, path=('Monthly Income', 'Good Food quality'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 17. Monthly Income vs Unaffordable
fig = px.sunburst(data_frame=df, path=('Monthly Income', 'Unaffordable'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 18. Family size vs Unavailability
fig = px.sunburst(data_frame=df, path=('Family size', 'Unavailability'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 19. Gender vs Unavailability
fig = px.sunburst(data_frame=df, path=('Gender', 'Unavailability'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
# 20. Gender vs Maximum wait time
fig = px.sunburst(data_frame=df, path=('Gender', 'Maximum wait time'))
fig.update_traces(textinfo='label+percent parent')
fig.show()
import pandas as pd
dd = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
dd.head(4)
| Date | Latitude | Longitude | Magnitude | |
|---|---|---|---|---|
| 0 | 01/02/1965 | 19.246 | 145.616 | 6.0 |
| 1 | 01/04/1965 | 1.863 | 127.352 | 5.8 |
| 2 | 01/05/1965 | -20.579 | -173.972 | 6.2 |
| 3 | 01/08/1965 | -59.076 | -23.557 | 5.8 |
df.head(4)
| Age | Gender | Marital Status | Occupation | Monthly Income | Educational Qualifications | Family size | latitude | longitude | Pin code | Medium (P1) | Medium (P2) | Meal(P1) | Meal(P2) | Perference(P1) | Perference(P2) | Ease and convenient | Time saving | More restaurant choices | Easy Payment option | More Offers and Discount | Good Food quality | Good Tracking system | Self Cooking | Health Concern | Late Delivery | Poor Hygiene | Bad past experience | Unavailability | Unaffordable | Long delivery time | Delay of delivery person getting assigned | Delay of delivery person picking up food | Wrong order delivered | Missing item | Order placed by mistake | Influence of time | Order Time | Maximum wait time | Residence in busy location | Google Maps Accuracy | Good Road Condition | Low quantity low time | Delivery person ability | Influence of rating | Less Delivery time | High Quality of package | Number of calls | Politeness | Freshness | Temperature | Good Taste | Good Quantity | Output | Reviews | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 20 | Female | Single | Student | No Income | Post Graduate | 4 | 12.9766 | 77.5993 | 560001 | Food delivery apps | Web browser | Breakfast | Lunch | Non Veg foods (Lunch / Dinner) | Bakery items (snacks) | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Agree | Agree | Agree | Agree | Agree | Agree | Yes | Weekend (Sat & Sun) | 30 minutes | Agree | Neutral | Neutral | Neutral | Neutral | Yes | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Yes | Nil\n |
| 1 | 24 | Female | Single | Student | Below Rs.10000 | Graduate | 3 | 12.9770 | 77.5773 | 560009 | Food delivery apps | Web browser | Snacks | Dinner | Non Veg foods (Lunch / Dinner) | Veg foods (Breakfast / Lunch / Dinner) | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Neutral | Agree | Strongly agree | Strongly agree | Agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Yes | Anytime (Mon-Sun) | 30 minutes | Strongly Agree | Neutral | Disagree | Strongly disagree | Agree | Yes | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Yes | Nil |
| 2 | 22 | Male | Single | Student | Below Rs.10000 | Post Graduate | 3 | 12.9551 | 77.6593 | 560017 | Food delivery apps | Direct call | Lunch | Snacks | Non Veg foods (Lunch / Dinner) | Ice cream / Cool drinks | Strongly agree | Strongly agree | Strongly agree | Neutral | Neutral | Disagree | Neutral | Disagree | Neutral | Neutral | Agree | Agree | Agree | Agree | Agree | Agree | Agree | Strongly agree | Agree | Neutral | Yes | Anytime (Mon-Sun) | 45 minutes | Agree | Strongly Agree | Neutral | Neutral | Agree | Yes | Important | Very Important | Moderately Important | Very Important | Very Important | Important | Very Important | Moderately Important | Yes | Many a times payment gateways are an issue, so... |
| 3 | 22 | Female | Single | Student | No Income | Graduate | 6 | 12.9473 | 77.5616 | 560019 | Food delivery apps | Walk-in | Snacks | Dinner | Veg foods (Breakfast / Lunch / Dinner) | Bakery items (snacks) | Agree | Agree | Strongly agree | Agree | Strongly agree | Agree | Agree | Agree | Strongly agree | Neutral | Agree | Disagree | Disagree | Neutral | Agree | Agree | Agree | Disagree | Disagree | Neutral | Yes | Anytime (Mon-Sun) | 30 minutes | Disagree | Agree | Agree | Neutral | Agree | Yes | Very Important | Important | Moderately Important | Very Important | Very Important | Very Important | Very Important | Important | Yes | nil |
import plotly.express as px
fig = px.density_mapbox(df, lat='latitude', lon='longitude', z='Age', radius=10,
center=dict(lat=0, lon=180), zoom=0,
mapbox_style="stamen-terrain")
fig.show()
Maximum Wait time¶replace
AgewithMaximum wait timeafter adjusting it to numerical values !
df['max_wait_min'] = df['Maximum wait time'].str.replace("minutes","").str.replace("more than","")
df['max_wait_min']
0 30
1 30
2 45
3 30
4 30
...
383 30
384 45
385 45
386 45
387 30
Name: max_wait_min, Length: 388, dtype: object
df.head(5)
| Age | Gender | Marital Status | Occupation | Monthly Income | Educational Qualifications | Family size | latitude | longitude | Pin code | Medium (P1) | Medium (P2) | Meal(P1) | Meal(P2) | Perference(P1) | Perference(P2) | Ease and convenient | Time saving | More restaurant choices | Easy Payment option | More Offers and Discount | Good Food quality | Good Tracking system | Self Cooking | Health Concern | Late Delivery | Poor Hygiene | Bad past experience | Unavailability | Unaffordable | Long delivery time | Delay of delivery person getting assigned | Delay of delivery person picking up food | Wrong order delivered | Missing item | Order placed by mistake | Influence of time | Order Time | Maximum wait time | Residence in busy location | Google Maps Accuracy | Good Road Condition | Low quantity low time | Delivery person ability | Influence of rating | Less Delivery time | High Quality of package | Number of calls | Politeness | Freshness | Temperature | Good Taste | Good Quantity | Output | Reviews | max_wait_min | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 20 | Female | Single | Student | No Income | Post Graduate | 4 | 12.9766 | 77.5993 | 560001 | Food delivery apps | Web browser | Breakfast | Lunch | Non Veg foods (Lunch / Dinner) | Bakery items (snacks) | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Neutral | Agree | Agree | Agree | Agree | Agree | Agree | Yes | Weekend (Sat & Sun) | 30 minutes | Agree | Neutral | Neutral | Neutral | Neutral | Yes | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Moderately Important | Yes | Nil\n | 30 |
| 1 | 24 | Female | Single | Student | Below Rs.10000 | Graduate | 3 | 12.9770 | 77.5773 | 560009 | Food delivery apps | Web browser | Snacks | Dinner | Non Veg foods (Lunch / Dinner) | Veg foods (Breakfast / Lunch / Dinner) | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Neutral | Agree | Strongly agree | Strongly agree | Agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Strongly agree | Yes | Anytime (Mon-Sun) | 30 minutes | Strongly Agree | Neutral | Disagree | Strongly disagree | Agree | Yes | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Very Important | Yes | Nil | 30 |
| 2 | 22 | Male | Single | Student | Below Rs.10000 | Post Graduate | 3 | 12.9551 | 77.6593 | 560017 | Food delivery apps | Direct call | Lunch | Snacks | Non Veg foods (Lunch / Dinner) | Ice cream / Cool drinks | Strongly agree | Strongly agree | Strongly agree | Neutral | Neutral | Disagree | Neutral | Disagree | Neutral | Neutral | Agree | Agree | Agree | Agree | Agree | Agree | Agree | Strongly agree | Agree | Neutral | Yes | Anytime (Mon-Sun) | 45 minutes | Agree | Strongly Agree | Neutral | Neutral | Agree | Yes | Important | Very Important | Moderately Important | Very Important | Very Important | Important | Very Important | Moderately Important | Yes | Many a times payment gateways are an issue, so... | 45 |
| 3 | 22 | Female | Single | Student | No Income | Graduate | 6 | 12.9473 | 77.5616 | 560019 | Food delivery apps | Walk-in | Snacks | Dinner | Veg foods (Breakfast / Lunch / Dinner) | Bakery items (snacks) | Agree | Agree | Strongly agree | Agree | Strongly agree | Agree | Agree | Agree | Strongly agree | Neutral | Agree | Disagree | Disagree | Neutral | Agree | Agree | Agree | Disagree | Disagree | Neutral | Yes | Anytime (Mon-Sun) | 30 minutes | Disagree | Agree | Agree | Neutral | Agree | Yes | Very Important | Important | Moderately Important | Very Important | Very Important | Very Important | Very Important | Important | Yes | nil | 30 |
| 4 | 22 | Male | Single | Student | Below Rs.10000 | Post Graduate | 4 | 12.9850 | 77.5533 | 560010 | Walk-in | Direct call | Lunch | Dinner | Non Veg foods (Lunch / Dinner) | Veg foods (Breakfast / Lunch / Dinner) | Agree | Agree | Agree | Agree | Agree | Neutral | Neutral | Agree | Strongly agree | Strongly agree | Agree | Strongly agree | Agree | Disagree | Strongly agree | Strongly agree | Neutral | Neutral | Neutral | Disagree | Yes | Weekend (Sat & Sun) | 30 minutes | Agree | Agree | Agree | Agree | Agree | Yes | Important | Important | Moderately Important | Important | Important | Important | Very Important | Very Important | Yes | NIL | 30 |
import plotly.express as px
fig = px.density_mapbox(df, lat='latitude', lon='longitude', z='max_wait_min', radius=10,
center=dict(lat=0, lon=180), zoom=0,
mapbox_style="stamen-terrain")
fig.show()
jupyter nbconvert Jupyter\ 6_Food_Delivery_Analysis.ipynb --to slides --post serve#----------------------------# Load Your Dependencies#--------------------------#
import dash
from jupyter_dash import JupyterDash # jupyter dash helps you to deploy dash on jupyter lab
from dash import dcc # Dash core Components
from dash import html # HTML for Layout and Fonts
import plotly.express as px # Plotly Graphs uses graph objects internally
from plotly.subplots import make_subplots
import plotly.graph_objects as go # Plotly Graph more customized
import pandas as pd # Pandas For Data Wrangling
from dash import Input, Output, dash_table # Input, Output for Call back functions
#--------------------------#Instanitiate Your App#--------------------------#
app = JupyterDash(__name__)
#--------------------------# Pandas Section #------------------------------#
df =pd.read_csv('onlinedeliverydata.csv')
group = ['Consumer demographics', 'Meal perefernces', 'Satisfaction', 'Not purchasing concerns', 'Cancellation concerns', 'Pereferences', 'Loyality']
demog = ['Age', 'Gender', 'Marital Status',"Occupation", 'Monthly Income', "Educational Qualifications", 'Family size']
peref= ['Medium (P1)', 'Medium (P2)', 'Meal(P1)', 'Meal(P2)', 'Perference(P1)', 'Perference(P2)']
satis = ['Ease and convenient', 'Time saving', 'More restaurant choices', 'Easy Payment option', 'More Offers and Discount', 'Good Food quality', 'Good Tracking system']
purc = ['Self Cooking', 'Health Concern', 'Late Delivery', 'Poor Hygiene', 'Bad past experience', 'Unavailability', 'Unaffordable']
canc = ['Long delivery time', 'Delay of delivery person getting assigned', 'Delay of delivery person picking up food', 'Wrong order delivered', 'Missing item', 'Order placed by mistake']
perf = ['Influence of time', 'Order Time', 'Maximum wait time', 'Residence in busy location', 'Google Maps Accuracy', 'Good Road Condition', 'Low quantity low time', 'Delivery person ability']
loyl = ['Influence of rating', 'Less Delivery time', 'High Quality of package', 'Number of calls', 'Politeness', 'Freshness ', 'Temperature', 'Good Taste ', 'Good Quantity', 'Output']
all_g = [demog, peref, satis, purc, canc, perf, loyl]
df_piv=pd.pivot_table(df,index=["Educational Qualifications","Occupation"], values=['Age','Family size'],
aggfunc=[np.median,len])
#df_piv.style.bar()
df_piv.reset_index().to_dict('rows')
#--------------------------------------------------------------------------#
app = JupyterDash(__name__)
app.layout = html.Div([html.Div([html.A([html.H2('Food Delivery Analysis Dashboard'),html.Img(src='/assets/logo1.png')], # A for hyper links
href='http://projectnitrous.com/')],className="banner"),
# First raw
html.Div([
html.H4('Univariate Analysis for the data groups', style={'color':'#ffffff'}),
], className="eleven columns", style={'padding':10}),
# Total Revenue
html.Div([
dcc.Dropdown(
id='dropdown_grp',
options=[{'label':group[i], 'value':i} for i in range(len(group))],
value=0,
multi=False,
searchable=True,
clearable=False
),
html.Div(
dcc.Graph(id='hist_grp'),
),
], className="eleven columns", style={'backgroundColor': '#2a2b4a', 'padding':10}),
#, 'border-radius': 25
html.Div([html.Br(),],className="eleven columns"),
# Second raw
html.Div([
html.H4('Multivariate Analysis', style={'color':'#ffffff'}),
], className="five columns", style={'padding':10}),
html.Div([
html.H4('Multivariate Analysis', style={'color':'#ffffff'}),
], className="five columns", style={'padding':10}),
# Multivariate Analysis
html.Div([
dcc.Dropdown(
id='dropdown_var1',
options=[{'label':i, 'value':i} for i in df.iloc[:,:7]],
value='Age',
multi=False,
searchable=True,
clearable=False
),
dcc.Dropdown(
id='dropdown_var2',
options=[{'label':i, 'value':i} for i in df.iloc[:,10:-2]],
value='Medium (P1)',
multi=False,
searchable=True,
clearable=False
),
html.Div(
dcc.Graph(id='sun_multi1'),
),
], className="five columns", style={'backgroundColor': '#2a2b4a', 'padding':10}),
# Multivariate Analysis
html.Div([
dcc.Dropdown(
id='dropdown_var3',
options=[{'label':i, 'value':i} for i in df[:7]],
value='Age',
multi=False,
searchable=True,
clearable=False
),
dcc.Dropdown(
id='dropdown_var4',
options=[{'label':i, 'value':i} for i in df[11:-2]],
value='Medium (P1)',
multi=False,
searchable=True,
clearable=False
),
html.Div(
dcc.Graph(id='sun_multi2'),
),
], className="five columns", style={'backgroundColor': '#2a2b4a', 'padding':10}),
html.Div([html.Br(),],className="eleven columns"),
# # Third raw
# html.Div([
# html.H4('Total quantity/store type & products', style={'color':'#003595'}),
# ], className="three columns", style={'padding':10}),
# html.Div([
# html.H4('Total quantity/store type & gender', style={'color':'#003595'}),
# ], className="three columns", style={'padding':10}),
# html.Div([
# html.H4('Total quantity/store type & age', style={'color':'#003595'}),
# ], className="three columns", style={'padding':10}),
# # Store type vs Products and Sub-Products
# html.Div([
# dcc.Dropdown(
# id='dropdown_prod',
# options=[
# {'label': 'Store type', 'value': 'Store_type'},
# {'label': 'Product', 'value': 'prod_cat'},
# {'label': 'Sub Product', 'value': 'prod_subcat'},
# ],
# value=['Store_type'],
# multi=True,
# searchable=True,
# clearable=False
# ),
# html.Div(
# dcc.Graph(id='sun_prod'),
# ),
# ], className="three columns", style={'backgroundColor': '#efedfa', 'border-radius': 25, 'padding':10}),
# # Store type vs Gender
# html.Div([
# dcc.Dropdown(
# id='dropdown_gen',
# options=[
# {'label': 'Store type', 'value': 'Store_type'},
# {'label': 'Gender', 'value': 'Gender'},
# ],
# value=['Store_type'],
# multi=True,
# searchable=True,
# clearable=False
# ),
# html.Div(
# dcc.Graph(id='sun_gen'),
# ),
# ], className="three columns", style={'backgroundColor': '#efedfa', 'border-radius': 25, 'padding':10}),
# # Store type vs Age
# html.Div([
# dcc.Dropdown(
# id='dropdown_age',
# options=[
# {'label': 'Store type', 'value': 'Store_type'},
# {'label': 'Age category', 'value': 'age_cat'},
# ],
# value=['Store_type'],
# multi=True,
# searchable=True,
# clearable=False
# ),
# html.Div(
# dcc.Graph(id='sun_age'),
# ),
# ], className="three columns", style={'backgroundColor': '#efedfa', 'border-radius': 25, 'padding':10}),
# html.Div([html.Br(),],className="eleven columns"),
# # Fourth raw
# html.Div([
# html.H4('Customers count per city', style={'color':'#003595'}),
# ], className="five columns", style={'padding':10}),
# html.Div([
# html.H4('Correlations between different fields affecting the clients', style={'color':'#003595'}),
# ], className="five columns", style={'padding':10}),
# # City & No. of Customers
# html.Div([
# dcc.Graph(id='hist_city'),
# ], className="five columns", style={'backgroundColor': '#efedfa', 'border-radius': 25, 'padding':10}),
# # Correlation Heatmap
# html.Div([
# dcc.Dropdown(
# id='dropdown_cor',
# options=[{'label':df.columns[i], 'value':df.columns[i]} for i in range(len(df.columns)) if (df[df.columns[i]].dtype== 'int64') or (df[df.columns[i]].dtype== 'float64')],
# value=['Qty', 'Rate'],
# multi=True,
# searchable=True,
# clearable=False
# ),
# html.Div(
# dcc.Graph(id='heatmap_cor'),
# ),
# ], className="five columns", style={'backgroundColor': '#efedfa', 'border-radius': 25, 'padding':10}),
# html.Div([html.Br(),],className="eleven columns"),
# # Fifth raw
# # Sentences
html.Div([
html.H4('The most and least values', style={'color':'#ffffff'}),
], className="eleven columns", style={'padding':10}),
html.Div([
# dcc.RadioItems(
# id='radio_value',
# options=[
# {'label': 'Highest value', 'value': 'most'},
# {'label': 'Lowest value', 'value': 'least'}
# ],
# value='most',
# labelStyle={'display': 'inline-block'}
# ),
# html.H4(html.Div(id='sent1')),
html.Div(
#dash_table.DataTable(df_piv.to_dict('records'), [{"name": i, "id": i} for i in df_piv.columns]),
),
], className="eleven columns", style={'backgroundColor': '#2a2b4a', 'padding':10}),
], className="twelve columns", style={'backgroundColor': '#1b203d', 'width':'100%', 'height':'100%', 'top':'0px', 'left':'0px'})
@app.callback(
Output('hist_grp', 'figure'),
Input('dropdown_grp', 'value'),
)
def grp_hist(value):
for i in range(len(all_g)):
if i == int(value):
col_len = len(all_g[i])
fig = make_subplots(rows=1, cols=col_len)
for x in range(1, col_len+1):
x_val=str(all_g[i][x-1])
fig.add_trace(px.histogram(df, x=x_val, barmode='group', labels=x_val, text_auto=True).data[0], row=1, col=x)
fig.update_layout({'paper_bgcolor': 'rgba(0, 0, 0, 0)'})
return fig
@app.callback(
Output('sun_multi1', 'figure'),
Input('dropdown_var1', 'value'),
Input('dropdown_var2', 'value'),
)
def multi1_sun(value1, value2):
fig = px.sunburst(data_frame=df, path=(value1, value2))
fig.update_traces(textinfo='label+percent parent')
fig.update_layout({'paper_bgcolor': 'rgba(0, 0, 0, 0)'})
return fig
@app.callback(
Output('sun_multi2', 'figure'),
Input('dropdown_var3', 'value'),
Input('dropdown_var4', 'value'),
)
def multi2_sun(value1, value2):
fig = px.sunburst(data_frame=df, path=(value1, value2))
fig.update_traces(textinfo='label+percent parent')
fig.update_layout({'paper_bgcolor': 'rgba(0, 0, 0, 0)'})
return fig
# @app.callback(
# Output('pv_table', 'children'),
# Input('pv_table', 'id'),
# )
# def table_pv(value):
# df_piv=pd.pivot_table(df,index=["Educational Qualifications","Occupation"], values=['Age','Family size'],
# aggfunc=[np.median,len])
# df_piv.style.bar()
# dash_piv = dash_table.DataTable(df_piv.to_dict('records'), [{"name": i, "id": i} for i in df_piv.columns])
# return dash_piv
app.run_server(mode='external')
C:\Users\Monmon\AppData\Local\Temp/ipykernel_11352/2200546115.py:31: FutureWarning:
Using short name for 'orient' is deprecated. Only the options: ('dict', list, 'series', 'split', 'records', 'index') will be used in a future version. Use one of the above to silence this warning.